<template>
  <div>
    <el-container class="el-container">
      <el-header class="el-header">
        <div>
          <img src="../assets/manager.png" alt="" />
          <span>电商管理系统</span>
        </div>
        <el-button type="primary" @click="logout">退出</el-button>
      </el-header>
      <el-container>
        <el-aside class="el-aside" :width="collapse ? '64px' : '300px'">
          <div class="elbutton" @click="isCollapse">|||</div>
          <el-row class="tac" style="width: 100%">
            <el-col :span="12" style="width: 100%">
              <el-menu
                background-color="#eee"
                active-text-color="#409EFF"
                :collapse="collapse"
                unique-opened
                router
              >
                <el-submenu
                  v-for="item in menus"
                  :index="item.id + ''"
                  :key="item.id"
                >
                  <template slot="title">
                    <i :class="iconObj[item.id]" style="margin-right: 15px"></i>
                    <span>{{ item.authName }}</span>
                  </template>
                  <el-menu-item-group>
                    <el-menu-item
                      :key="subItem.path"
                      :index="subItem.path + ''"
                      v-for="subItem in item.children"
                    >
                      <i class="el-icon-document"></i>
                      <span>{{ subItem.authName }}</span></el-menu-item
                    >
                  </el-menu-item-group>
                </el-submenu>
              </el-menu>
            </el-col>
          </el-row>
        </el-aside>
        <el-main class="el-main"><router-view></router-view></el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
export default {
  data() {
    return {
      //左侧菜单数据
      menus: [],
      iconObj: {
        125: "el-icon-document",
        103: "el-icon-info",
        101: "el-icon-message",
        102: "el-icon-mobile-phone",
        145: "el-icon-printer",
      },
      collapse: false,
    };
  },

  methods: {
    isCollapse() {
      this.collapse = !this.collapse;
    },
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    //获取左侧菜单数据
    async getMenuList() {
      const { data: res } = await this.$http.get("menus");
      console.log(res);
      if (res.meta.status != 200) return this.$message.error("获取菜单失败");
      this.menus = res.data;
    },
  },
  mounted() {
    this.getMenuList();
  },
};
</script>

<style scoped>
.el-header {
  background: rgb(50, 51, 51);
  display: flex;
  justify-content: space-between;
  font-size: 20px;
  color: rgb(217, 235, 231);
  align-items: center;
}
img {
  width: 60px;
  height: 100%;
  border-radius: 50%;
}
.el-header div {
  display: flex;
  align-items: center;
}
.el-header div span {
  margin-left: 15px;
}
.el-container {
  height: 100vh;
}
.el-aside {
  background: rgb(110, 107, 107);
}
.elbutton {
  text-align: center;
}
</style>